package com.smm.web.vmc.handler;


import java.io.Serializable;
import java.util.Date;

/**
 * Created by zhenghao on 2016/9/12.
 *
 */

public class TagInfo implements Serializable {

    private String tagNo;   //标签编号


    private boolean shock;  //是否震动


    private Date time; //震动时间

    public TagInfo(String tagNo, boolean shock) {
        this.tagNo = tagNo;
        this.shock = shock;
        this.time = new Date();
    }

    public String getTagNo() {
        return tagNo;
    }

    public void setTagNo(String tagNo) {
        this.tagNo = tagNo;
    }

    public boolean isShock() {
        return shock;
    }

    public void setShock(boolean shock) {
        this.shock = shock;
    }

    public Date getTime() {
        return time;
    }

    public void setTime(Date time) {
        this.time = time;
    }



    //解析数据
    public static TagInfo decodeMessage(String msg) {

        if (msg.length() != 40) {
            return null;
        }
        try {
            // 13 00 00 03000099 00 cc02a304fcffebff02ff78e3
            // 130000030000ea00c202dd040d00f4fffafe4c41

            String rfidCode = msg.substring(6, 14);

            String shock = msg.substring(14, 16);

            boolean isShock = shock.equals("01");

            return new TagInfo(rfidCode.toUpperCase(),isShock);

        } catch (Exception e) {

            e.printStackTrace();
        }

        return null;
    }
}
